package com.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/demo04.do")
public class Demo04Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Demo04Servlet doGet()");
        String username = req.getParameter("username");
        //往request域对象中存值
        req.setAttribute("u1", "123456");
        //获取请求转发对象
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("/demo05.do");
        //把当前request对象原封不动的转发到另一个Servlet
        requestDispatcher.forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Demo04Servlet doPost()");
        String username = req.getParameter("username");
        //往request域对象中存值
        req.setAttribute("u1", "123456");
        //获取请求转发对象
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("/demo05.do");
        //把当前request对象原封不动的转发到另一个Servlet
        requestDispatcher.forward(req, resp);
    }
}
